/*
 * @Description: 档案导出管理类型导航
 * @Author: Rfan
 * @Date: 2022-06-21 21:37:30
 * @LastEditTime: 2022-06-23 18:26:04
 */

import { Menu } from 'antd';
import cs from 'classnames';
import { useExportMgtContext } from '../contexts/ExportMgtContext';
import type { MenuInfo } from 'rc-menu/lib/interface';
import { EnumReceiveTypes } from '@/dictionary/transfer';
import { IBaseDic } from '@/interfaces/global';

const PageSidebar = (props: any) => {
  const { className } = props;
  const { selectExportType, exportTypeList, setSelectExportType } = useExportMgtContext();
  const items = exportTypeList
    .filter((item: IBaseDic) => item.id !== EnumReceiveTypes.DBF)
    .map((item: IBaseDic) => ({ label: item.name, key: item.id }));

  /**
   * @description: 切换导出类型
   * @param {MenuInfo} param 点击条目信息
   */
  const changeNav = ({ key }: MenuInfo) => {
    setSelectExportType(parseInt(key, 10));
  };

  return (
    <>
      <Menu
        className={cs('export-sidebar', className)}
        items={items}
        selectedKeys={[`${selectExportType}`]}
        onClick={changeNav}
      />
    </>
  );
};

export default PageSidebar;
